export const uploadMixin = {
  data () {
    return {
      autoWidth: true,
      bookType: 'xlsx',
      keyMap: {},
      currentUpload: ''
    }
  },
  methods: {
    // 模版下载
    handleDownload (filename, keyMap) {
      this.downloadLoading = true
      import('@/vendor/Export2Excel').then((excel) => {
        const tHeader = []
        const filterVal = []
        const list = []
        if (filename === '主要获奖模版') {
          list.push({
            grade: '123'
          })
        }
        Object.keys(keyMap).forEach((key) => {
          tHeader.push(key)
          filterVal.push(keyMap[key])
        })
        const data = this.formatJson(filterVal, list)
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename,
          autoWidth: this.autoWidth,
          bookType: this.bookType
        })
        this.downloadLoading = false
      })
    },
    // 上传
    handleUpload (name) {
      this.currentUpload = name
      this.$refs.upload.handleUpload()
    },
    // 处理导出数据格式
    formatJson (filterVal, jsonData) {
      return jsonData.map((v) =>
        filterVal.map((j) => {
          if (j === 'timestamp') {
            return v[j]
            // return parseTime(v[j])
          } else {
            return v[j]
          }
        })
      )
    }
  }
}
